import Aplayer from "aplayer"
import React, { useRef } from "react"
import "aplayer/dist/APlayer.min.css"
export interface usesAplayerConfig {
  container: React.MutableRefObject<any> //根节点
  [key: string]: any
}
const useAplayer = ({
  container,
  ...otrconfig
}: usesAplayerConfig): [any | undefined] => {
  const aplayerInstance = useRef<any>()
  React.useEffect(() => {
    aplayerInstance.current = new Aplayer({
      container: container.current ?? undefined,
      ...otrconfig,
    })
  }, [container.current])
  return [aplayerInstance.current]
}

export { useAplayer }
